package com.cao.springbootinit.controller;

import com.cao.springbootinit.common.BaseResponse;
import com.cao.springbootinit.common.ErrorCode;
import com.cao.springbootinit.common.ResultUtils;
import com.cao.springbootinit.exception.ThrowUtils;
import com.cao.springbootinit.service.UserAnswerService;
import com.cao.springbootinit.statistic.AppAnswerCountDto;
import com.cao.springbootinit.statistic.AppAnswerResultCountDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * App统计接口
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
@RestController
@RequestMapping("/app/statistic")
@Slf4j
public class AppStatisticController {
    @Resource
    private UserAnswerService userAnswerService;

    /**
     * 热门应用回答统计
     * @return
     */
    @GetMapping("/answer_count")
    public BaseResponse<List<AppAnswerCountDto>> getAppAnswerCount() {
        return ResultUtils.success(userAnswerService.selectAllCount());
    }

    /**
     * 某应用回答及结果统计
     * @param appId
     * @return
     */
    @GetMapping("/answer_result_count")
    public BaseResponse<List<AppAnswerResultCountDto>> getAppAnswerResultCount(Long appId) {
        ThrowUtils.throwIf(appId == null || appId <= 0, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerService.doAppAnswerResultCount(appId));
    }
}
